<style>

    .mainPanel{
        padding: 10px 0;
        width:100%;
        height:300px;
        float:left;
    }
    
    .userWarehousePanel{
        width:280px;
        height:100%;
        display:block;
        float:left;
        border:solid 1px #ededed;
        overflow:auto;
    }
    
</style>

<div class="pageContent">
    <form method="post"
        action="${rc.getContextPath()}/manage/userWarehouse/saveUserWarehouse"
        class="pageForm required-validate"
        onsubmit="return checkUserWarehouseNotExists() && validateCallback(this, dialogAjaxDone);">
        <div class="pageFormContent" >
            <input type="hidden" name="navTabId" value="${navTabId!''}">
            <input type="hidden" name="id"
                value="<#if (userWarehouse.warehouseCode)??>${userWarehouse.warehouseCode!''}</#if>">
            <fieldset>
                <dl>
                    <dt><@label key="userCode.C,colon">用户编号：</@label></dt>
                    <dd>
                        <input name="userCode" value="${userWarehouse.userCode!''}" 
                              size="22" type="text" maxlength="40" class="required  alphanumeric toUp" 
                               id="userWarehouseLookup.userCode"
                              postField="userCode" suggestFields="userCode,userText" 
                              suggestUrl="${rc.getContextPath()}/manage/user/userSuggest" lookupGroup="userWarehouseLookup"
                              remote="${rc.getContextPath()}/manage/user/checkedUserCodeNotExits"
                              warn="<@label key='userCode.C,doesNotExist.C'>用户编号不存在</@label>"
                              <#if userWarehouse??>
                                  readonly="readonly"
                              <#else>
                                  remote="${rc.getContextPath()}/manage/user/userSuggest"
                             </#if>
                        />
                    </dd>
                </dl>
                <dl>
                    <dt><@label key="userText.C,colon">用户描述：</@label></dt>
                    <dd>
                        <input name="userText"
                            value="${userWarehouse.userText!''}" id="userWarehouseLookup.userText"
                            size="22" type="text" maxlength="60" class="required" 
                              readonly="readonly"
                          />
                    </dd>
                </dl>
                <dl>
                    <dt>仓库：</dt>
                    <dd>
                        <input name="warehouseCode" type="text" class="required" readonly="readonly"/>
                    </dd>
                </dl>
                <dl>
                    <dt><@label key="moveType.C,colon">移动类型：</@label></dt>
                </dl>
                <div class="mainPanel">
                    <div id="warehouse" class="userWarehousePanel" style="margin-right:10px;">
                        <ul class="tree treeFolder expand">
                        <#if warehouseTypes??&&(warehouseTypes?size) gt 0> 
                          <#list warehouseTypes as type>
                            <li>
                                <a name="warehouseType">
                                    ${type.warehouseTypeCode}-${type.warehouseTypeText}
                                </a> 
                                <#if type.warehouses??&&(type.warehouses?size) gt 0>
                                    <ul>
                                    <#list type.warehouses as warehouse>
                                        <li>    
                                            <a name="warehouse" tvalue="${warehouse.warehouseCode}" >
                                                ${warehouse.warehouseCode}-${warehouse.warehouseText}
                                            </a> 
                                        </li> 
                                    </#list>
                                    </ul> 
                                </#if>
                            </li>
                            </#list> 
                        </#if>
                        </ul>
                    </div>
                    <div id="moveTypeSelect" class="userWarehousePanel" style="margin-left:10px;">
                        <ul id="tree" class="tree treeFolder treeCheck expand">
                            <#if moveTypeMap??&&(moveTypeMap?size) gt 0>
                                <li>
                                    <a><@label key="selectAll.C">全选</@label></a> 
                                    <ul>
                                 <#list moveTypeMap?keys as key>
                                        <li>
                                            <a>${eCodesMap[key]}</a> 
                                            <ul>
                                              <#list moveTypeMap[key] as mt>
                                                <li>
                                                    <a tvalue="${mt.moveTypeCode}" tname="moveTypeCodes">${mt.moveTypeCode}-${mt.moveTypeText}</a> 
                                                </li>
                                              </#list>
                                            </ul>
                                     </li>                 
                                 </#list>
                            </#if>
                        </ul>
                        </li>
                        </ul>
                    </div>
                  </div>
                </dl>
            </fieldset>
        </div>
        <#if userWarehouse??>
            <#assign createInfo=userWarehouse>
            <#include "/common/createInfo.html">
        </#if>
        <div class="formBar">
            <ul>
                    <li>
                        <div class="buttonActive">
                            <div class="buttonContent">
                                <button type="submit"><@label key="save.B">保存</@label></button>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="buttonActiveGrey">
                            <div class="buttonContent">
                                    <button type="button" class="close"><@label key="cancel.B">取消</@label></button>
                            </div>
                        </div>
                    </li>
            </ul>
        </div>
    </form>
</div>
<script>

var dialog=$.pdialog.getCurrent();
var $userCode=$("input[name=userCode]",dialog);
var $warehouse=$("input[name=warehouseCode]",dialog);
var checkUserWarehouseNotExists=function(){
    var checkOk=true;
    $.ajax({
        url:hostUrl +"/userWarehouse/checkWarehouseNotAssigned",
        async:false,
        data:{warehouseCode: $warehouse.val(), userCode: $userCode.val()},
        success:function(data){
            checkOk=data;
        }
    });
    
    if(checkOk){
        return true;
    }
    else
    {
        alertMsg.warn("该用户仓库权限已存在！");
        return false;
    }
};

$("a[name=warehouse]",dialog).click(function(){
    $warehouse.val($(this).attr("tvalue"));
});
/* var checkUserWarehouseNotExists=function(warehouseCode,source){
    var $userCode=$("input[name=userCode]",dialog);
    var $warehouse=$("input[name=warehouseCode]",dialog);
    var checkOk=true;
    $.ajax({
        url:hostUrl +"/userWarehouse/checkWarehouseNotAssigned",
        async:false,
        data:{warehouseCode: warehouseCode, userCode: $userCode.val()},
        success:function(data){
            checkOk=data;
        }
    });
    
    if(checkOk){
        
        $warehouse.val(warehouseCode);
    }
    else
    {
        if('userCode'===source)
        {
            alertMsg.warn("该用户："+$userCode.val()+"仓库权限已存在！");
            $userCode.val('');
        }
        else
        {
            alertMsg.warn("该用户仓库："+warehouseCode+"权限已存在！");
            $warehouse.val('');
        }
    }
    
};


$("input[name=userCode]",dialog).change(function(){
    var warehouseCode=$("input[name=warehouseCode]",dialog).val();
    checkUserWarehouseNotExists(warehouseCode,'userCode');
});


$("a[name=warehouse]",dialog).click(function(){
    var warehouseCode=$(this).attr("tvalue");
    checkUserWarehouseNotExists(warehouseCode,'warehouse');
});

$("a[name=warehouseType]",dialog).click(function(){
    $("input[name=warehouseCode]",dialog).val('');
});
     */    

</script>
